/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidades;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author lomanda
 */
@Entity
@Table(name = "compra")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"),
    @NamedQuery(name = "Compra.findByIdCompra", query = "SELECT c FROM Compra c WHERE c.idCompra = :idCompra"),
    @NamedQuery(name = "Compra.findByDescricaoCompra", query = "SELECT c FROM Compra c WHERE c.descricaoCompra = :descricaoCompra"),
    @NamedQuery(name = "Compra.findByPreco", query = "SELECT c FROM Compra c WHERE c.preco = :preco")})
public class Compra implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "idCompra")
    private Integer idCompra;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "descricaoCompra")
    private String descricaoCompra;
    @Basic(optional = false)
    @NotNull
    @Column(name = "preco")
    private double preco;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra")
    private List<ItemCompra> itemCompraList;
    @JoinColumn(name = "fkFuncionario", referencedColumnName = "idFuncionario")
    @ManyToOne(optional = false)
    private Funcionario fkFuncionario;
    @JoinColumn(name = "fkidFornecedor", referencedColumnName = "idFornecedor")
    @ManyToOne(optional = false)
    private Fornecedor fkidFornecedor;
    @JoinColumn(name = "fkEncomenda", referencedColumnName = "idEncomenda")
    @ManyToOne(optional = false)
    private Encomenda fkEncomenda;

    public Compra() {
    }

    public Compra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public Compra(Integer idCompra, String descricaoCompra, double preco) {
        this.idCompra = idCompra;
        this.descricaoCompra = descricaoCompra;
        this.preco = preco;
    }

    public Integer getIdCompra() {
        return idCompra;
    }

    public void setIdCompra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public String getDescricaoCompra() {
        return descricaoCompra;
    }

    public void setDescricaoCompra(String descricaoCompra) {
        this.descricaoCompra = descricaoCompra;
    }

    public double getPreco() {
        return preco;
    }

    public void setPreco(double preco) {
        this.preco = preco;
    }

    @XmlTransient
    public List<ItemCompra> getItemCompraList() {
        return itemCompraList;
    }

    public void setItemCompraList(List<ItemCompra> itemCompraList) {
        this.itemCompraList = itemCompraList;
    }

    public Funcionario getFkFuncionario() {
        return fkFuncionario;
    }

    public void setFkFuncionario(Funcionario fkFuncionario) {
        this.fkFuncionario = fkFuncionario;
    }

    public Fornecedor getFkidFornecedor() {
        return fkidFornecedor;
    }

    public void setFkidFornecedor(Fornecedor fkidFornecedor) {
        this.fkidFornecedor = fkidFornecedor;
    }

    public Encomenda getFkEncomenda() {
        return fkEncomenda;
    }

    public void setFkEncomenda(Encomenda fkEncomenda) {
        this.fkEncomenda = fkEncomenda;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompra != null ? idCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.idCompra == null && other.idCompra != null) || (this.idCompra != null && !this.idCompra.equals(other.idCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Compra[ idCompra=" + idCompra + " ]";
    }
    
}
